<template>
  <div class="accordion">
    <div class="accordion-item" v-for="(item, index) in items" :key="index">
      <div class="accordion-title" @click="toggleItem(index)" :class="{ active: activeIndex === index }">
        <div class="accordion-title-lt">
          {{ item.title }}
        </div>
        <div class="accordion-title-rt">
          <div class="accordion-title-rt-text">
            {{item.time }}
          </div>
          <div class="accordion-title-rt-img">
            <img class="up" v-if="activeIndex === index" src="@/assets/up.png" alt="" />
            <img class="down" v-else src="@/assets/down.png" alt="" />
          </div>

        </div>
      </div>
      <div class="accordion-content" v-show="activeIndex === index">
        <div class="cont-lt">
          <div class="cont-lt-tp">
            成交均价:{{ item.price }}
          </div>
          <div class="cont-lt-bt">
           买卖:{{ item.typeText }}
          </div>
        </div>
        <div class="cont-rt">
          <div class="cont-rt-tp">
             服务费：{{ item.fee }}
          </div>
          <div class="cont-rt-bt">
             成交数量:{{ item.number}}
          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Accordion',
    props: {
      items: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        activeIndex: -1
      }
    },
    methods: {
      toggleItem(index) {
        console.log(index)
        if (index === this.activeIndex) {
          this.activeIndex = -1;
        } else {
          this.activeIndex = index;
        }
      }
    }
  }
</script>

<style scoped>
  .accordion{
    background-color: #F7F7F7;
  }
  .accordion-content {
    display: flex;
    justify-content: space-between;
    align-items: center;

    cursor: pointer;
    border-bottom: 1px solid #ccc;
  }

  .accordion-content .cont-lt {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    font-size: 28px;
    color: #5E5E5E;
    padding: 30px 0 30px 20px;
  }
.accordion-content .cont-lt .cont-lt-tp{
    font-size: 28px;
    color: #5E5E5E;
  }
  .accordion-content .cont-lt .cont-lt-bt{
      font-size: 28px;
      color: #5E5E5E;
      padding-top: 5px;
    }
  .accordion-content .cont-rt {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    font-size: 28px;
    color: #5E5E5E;
    padding: 30px 20px 30px 0;
  }
.accordion-content .cont-rt .cont-rt-tp{
    font-size: 28px;
    color: #5E5E5E;
  }
  .accordion-content .cont-rt .cont-rt-bt{
      font-size: 28px;
      color: #5E5E5E;
      padding-top: 5px;
    }
  .accordion-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px;
    cursor: pointer;
    border-bottom: 1px solid #ccc;
  }

  .accordion-title-lt {
    font-size: 30px;
    color: #373737;
    font-weight: 600;
  }

  .accordion-title .accordion-title-rt {
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }

  .accordion-title .accordion-title-rt .accordion-title-rt-text {
    font-size: 28px;
    color: #5A5A5A;
  }

  .accordion-title .accordion-title-rt .accordion-title-rt-img img {
    width: 30px;
    height: 30px;
    position: relative;
    top: 3px;
    margin-left: 40px;
  }

  .accordion-content {
    padding: 10px;
    /* display: none; */
  }

  .active .accordion-content {
    /* display: block; */
  }
</style>
